
#ifndef RTTRANSPORTBASE_H
#define RTTRANSPORTBASE_H

#include "RtReactorInterface.h"
#include "RtConnectionInterface.h"
#include "RtReferenceControl.h"
#include "RtTimerWrapper.h"
#include "RtTimeValue.h"
#include "RtUtilTemplates.h"

class CRtSocketBase;

class /*RT_API_EXPORT*/ CRtTransportBase 
	: public IRtEventHandler
	, public IRtTransport
	, public CRtReferenceControlSingleThreadTimerDelete
{
public:
	CRtTransportBase(IRtReactor *pReactor);
	virtual ~CRtTransportBase();

	// interface IRtReferenceControl
	virtual DWORD AddReference();
	virtual DWORD ReleaseReference();

	// interface IRtTransport
	virtual RtResult OpenWithSink(IRtTransportSink *aSink);
	virtual IRtTransportSink* GetSink();
	virtual RtResult GetOption(DWORD aCommand, LPVOID aArg);
	virtual RtResult Disconnect(RtResult aReason);
	
	// interface IRtEventHandler
	virtual int OnClose(RT_HANDLE aFd, MASK aMask);

#ifdef RT_SUPPORT_QOS
	RtResult SetQos2Socket(RT_HANDLE aSocket);
#endif // RT_SUPPORT_QOS

	RtResult SetTos2Socket(CRtSocketBase &aSocket, LPVOID aArg);

protected:
	// template method for open() and close()
	virtual RtResult Open_t() = 0;
	virtual RtResult Close_t(RtResult aReason) = 0;

	IRtTransportSink *m_pSink;
	IRtReactor *m_pReactor;

/***********Jobs Add at 2008.06.03 for flow control************************/
	DWORD	m_dwTotalSend;
	LONGLONG	m_dwLastSendCalTime;
	DWORD	m_dwTotalRecv;
	LONGLONG	m_dwLastRecvCalTime;
	DWORD	m_dwLastRecvRate;
	DWORD	m_dwLastSendRate;
/***********Jobs Add at 2008.06.03 End************************/
};

#endif // !RTTRANSPORTBASE_H
